define(function (require, exports, module) {
	require('artDialog');
	var $ = require('$');
	var util = require("lm-util");

	exports.thumb_images = function (uploadid, returnid) {
		var d = window.top.art.dialog({id : uploadid}).data.iframe;
		var in_content = d.$("#att-status").html().substring(1);
		if ( in_content == '' ) return false;
		if ( !util.IsImg(in_content) ) {
			alert('选择的类型必须为图片类型');
			return false;
		}
		if ( $('#' + returnid + '_preview').attr('src') ) {
			$('#' + returnid + '_preview').attr('src', in_content);
		}
		$('#' + returnid).val(in_content);
	}

	exports.change_images = function (uploadid, returnid) {
		var d = window.top.art.dialog({id : uploadid}).data.iframe;
		var in_content = d.$("#att-status").html().substring(1);
		var in_filename = d.$("#att-name").html().substring(1);
		var str = $('#' + returnid).html();
		var contents = in_content.split('|');
		var filenames = in_filename.split('|');
		$('#' + returnid + '_tips').css('display', 'none');
		if ( contents == '' ) return true;
		$.each(contents, function (i, n) {
			var ids = parseInt(Math.random() * 10000 + 10 * i);
			var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
			str += "<p class='multi-imgs' id='image" + ids + "'>" +
                "<img src='" + n + "' height='80' title='双击查看原图' ><br>"+
				"<input type='hidden' name='" + returnid + "_url[]' value='" + n + "' style='width:310px;' class='input-text'> " +
				"<input type='text' name='" + returnid + "_alt[]' value='" + filename + "' style='width:160px;' class='input-text' onfocus=\"if(this.value == this.defaultValue) this.value = ''\" onblur=\"if(this.value.replace(' ','') == '') this.value = this.defaultValue;\"> <br />" +
				"<a data-removeId = 'image" + ids + "' href='javascript:void(0)'>移除</a> " +
				"</p>";
		});

		$('#' + returnid).html(str);
	}

	/**
	 * 预览
	 * @param img
	 */
	exports.image_preview = function(img) {
		window.top.art.dialog({title : '图片查看', fixed:true,  content : '<img src="' + img + '" />', id : 'image_preview'});
	};

	exports.remove_div = function (id) {
		$('#' + id).remove();
	};

	/**
	 * @param uploadid      上传组件Id
	 * @param name          对话框title
	 * @param textareaid    textareaid
	 * @param funcName      上传函数
	 * @param args          参数
	 */
	exports.flashupload = function (url,uploadid, name, textareaid, funcName) {
		window.top.art.dialog({
			title : name,
			id : uploadid,
			iframe : url,
			width : '500',
			height : '420'
		},function () {
			if ( funcName ) {
				funcName.apply(this, [uploadid, textareaid]);
			} else {
				alert("arguments error")
			}
		}, function () {
			window.top.art.dialog({id : uploadid}).close();
		});
	};

	function submit_images(uploadid, returnid) {
		var d = window.top.art.dialog({id : uploadid}).data.iframe;
		var in_content = d.$("#att-status").html().substring(1);
		var in_content = in_content.split('|');
		util.IsImg(in_content[0]) ? $('#' + returnid).attr("value", in_content[0]) : alert('选择的类型必须为图片类型');
	}

	function close_window() {
		if ( $('#title').val() != '' ) {
			art.dialog({content : '内容已经录入，确定离开将不保存数据！', fixed : true, yesText : '我要关闭', noText : '返回保存数据', style : 'confirm', id : 'bnt4_test'}, function () {
				window.close();
			}, function () {

			});
		} else {
			window.close();
		}
		return false;
	}

});
